﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PointTracker;

namespace PointTracker.Controls
{
    public partial class TopToolbar : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        public void VerifyUser(Object sender, EventArgs e)
        {
            // DB authentication
            if (!TextBoxUserEmail.Text.Equals("") && !TextBoxPassword.Text.Equals(""))
            {
                PointTracker.User u = PointTracker.User.getUserInstance(TextBoxUserEmail.Text, TextBoxPassword.Text);
                if (u == null)
                {
                    Response.Redirect("~/Error/");
                }
                Session["User"] = u;
                if (u.role == UserRole.Professor)
                {
                    Response.Redirect("~/professor.aspx");
                }
                else if (u.role == UserRole.Admin)
                {
                    Response.Redirect("~/Admin.aspx");
                }
                else if (u.role == UserRole.Scribe)
                {
                    Response.Redirect("~/Scribe.aspx");
                }
                else
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
            else  //Error occured
                Response.Redirect("~/Error/");
        }

    }
}